package com.metal.silver.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.metal.silver.domain.CustomerVisit;
import com.metal.silver.service.ICustomerVisitService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户拜访单Controller
 * 
 * @author Kelvin
 * @date 2022-10-20
 */
@Controller
@RequestMapping("/silver/visit")
public class CustomerVisitController extends BaseController
{
    private String prefix = "silver/visit";

    @Autowired
    private ICustomerVisitService customerVisitService;

    @RequiresPermissions("silver:visit:view")
    @GetMapping()
    public String visit()
    {
        return prefix + "/visit";
    }

    /**
     * 查询客户拜访单列表
     */
    @RequiresPermissions("silver:visit:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CustomerVisit customerVisit)
    {
        startPage();
        List<CustomerVisit> list = customerVisitService.selectCustomerVisitList(customerVisit);
        return getDataTable(list);
    }

    /**
     * 导出客户拜访单列表
     */
    @RequiresPermissions("silver:visit:export")
    @Log(title = "客户拜访单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CustomerVisit customerVisit)
    {
        List<CustomerVisit> list = customerVisitService.selectCustomerVisitList(customerVisit);
        ExcelUtil<CustomerVisit> util = new ExcelUtil<CustomerVisit>(CustomerVisit.class);
        return util.exportExcel(list, "客户拜访单数据");
    }

    /**
     * 新增客户拜访单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存客户拜访单
     */
    @RequiresPermissions("silver:visit:add")
    @Log(title = "客户拜访单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CustomerVisit customerVisit)
    {
        return toAjax(customerVisitService.insertCustomerVisit(customerVisit));
    }

    /**
     * 修改客户拜访单
     */
    @RequiresPermissions("silver:visit:edit")
    @GetMapping("/edit/{uuid}")
    public String edit(@PathVariable("uuid") String uuid, ModelMap mmap)
    {
        CustomerVisit customerVisit = customerVisitService.selectCustomerVisitByUuid(uuid);
        mmap.put("customerVisit", customerVisit);
        return prefix + "/edit";
    }

    /**
     * 修改保存客户拜访单
     */
    @RequiresPermissions("silver:visit:edit")
    @Log(title = "客户拜访单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CustomerVisit customerVisit)
    {
        return toAjax(customerVisitService.updateCustomerVisit(customerVisit));
    }

    /**
     * 删除客户拜访单
     */
    @RequiresPermissions("silver:visit:remove")
    @Log(title = "客户拜访单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(customerVisitService.deleteCustomerVisitByUuids(ids));
    }
}
